﻿/**
* exceptionHandleService - AngularJS module for web api management.
*
*
* Credits
* =======
*
* Copyright 2016 LonghronShen <LonghronShen@Hotmail.com>
*/

(function () {
    "use strict";

    /**
     * Config
     */
    var moduleName = 'ccp';
    var DEFAULT_ID = '__default';

    /**
     * Module
     */
    var module;
    try {
        module = angular.module(moduleName);
    } catch (err) {
        // named module does not exist, so create one
        module = angular.module(moduleName, []);
    }
    
    module.service('exceptionHandleService', ["$rootScope", '$window', '$ngBootbox', '$state', function ($rootScope, $window, $ngBootbox, $state) {
        return {
            request: function (res) {
                var errorCode = res.data.Error ? res.data.Error.Code : null;
                if (errorCode == 42001) {
                    $ngBootbox.alert("您已经被踢下线，请您重新登录！");
                    $state.go("access.signin");
                }
            }
        };
    }]);
})();